;import symbols
(import 'sys/symbols.inc)

;some simple structure helpers
(defmacro structure (n o &rest b)
	`(progn (defq _e (env) _n ,n _o ,(eval o)) ~b (def _e (sym (cat _n "_size")) _o '_e nil)))
(defun struct (s &rest b)
	(each (lambda (_) (def _e (sym (cat _n "_" _)) _o) (setq _o (+ _o s))) b))
(defun offset (&rest b)
	(apply struct (cat (list 0) b)))
(defun ptr (&rest b)
	(setq _o (align _o ptr_size)) (apply struct (cat (list ptr_size) b)))
(defun long (&rest b)
	(setq _o (align _o long_size)) (apply struct (cat (list long_size) b)))
(defun int (&rest b)
	(setq _o (align _o int_size)) (apply struct (cat (list int_size) b)))
(defun short (&rest b)
	(setq _o (align _o short_size)) (apply struct (cat (list short_size) b)))
(defun byte (&rest b)
	(setq _o (align _o byte_size)) (apply struct (cat (list byte_size) b)))

;system lisp bindings
(ffi kernel-declare "sys/kernel/lisp_declare" 0)
(ffi kernel-total "sys/kernel/lisp_total" 0)
(ffi mail-declare "sys/mail/lisp_declare" 0)
(ffi mail-enquire "sys/mail/lisp_enquire" 0)
(ffi mail-poll "sys/mail/lisp_poll" 0)
(ffi mail-read "sys/mail/lisp_read" 0)
(ffi mail-select "sys/mail/lisp_select" 0)
(ffi mail-send "sys/mail/lisp_send" 0)
(ffi mail-alloc-mbox "sys/mail/lisp_alloc_mbox" 0)
(ffi mail-free-mbox "sys/mail/lisp_free_mbox" 0)
(ffi open-child "sys/task/lisp_open_child" 0)
(ffi open-farm "sys/task/lisp_open_farm" 0)
(ffi open-pipe "sys/task/lisp_open_pipe" 0)
(ffi open-remote "sys/task/lisp_open_remote" 0)
(ffi pii-read-char "sys/pii/lisp_readchar" 0)
(ffi pii-write-char "sys/pii/lisp_writechar" 0)
(ffi task-mailbox "sys/task/lisp_mailbox" 0)
(ffi task-sleep "sys/task/lisp_sleep" 0)
(ffi mem-stats "sys/mem/lisp_stats" 0)
